/**
 *
 */
package jp.seraph.cui;

/**
 *
 *
 */
public class CdCommand extends AbstractCommand implements Command {
    public CdCommand(Mode aParent, InternalConsole aConsole){
        super(aParent, aConsole);
    }

    /**
     *
     * @see jp.seraph.cui.AbstractCommand#executeImpl(jp.seraph.cui.SystemNode[])
     */
    @Override
    protected void executeImpl(SystemNode[] aArgs, int aArgListIndex) {
        InternalConsole tConsole = getConsole();
        ConsoleContext tContext = tConsole.getContext();
        Mode tMode = null;
        
        if(aArgListIndex == 0)
            tMode = (Mode)aArgs[0];
        else
            tMode = tContext.getMode();

        tContext.setMode(tMode);
    }

    /**
     *
     * @see jp.seraph.cui.Command#getArgumentTypes()
     */
    public SystemNodeType[][] getArgumentTypes() {
        return new SystemNodeType[][]{
                    new SystemNodeType[]{ModeType.getInstance()},
                    new SystemNodeType[0]
                };
    }

    /**
     *
     * @see jp.seraph.cui.Command#getHelp()
     */
    public String getHelp() {
        return "cd arg : change mode to arg";
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getName()
     */
    public String getName() {
        return "cd";
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getType()
     */
    public SystemNodeType getType() {
        return CdCommandType.getInstance();
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#isRoot()
     */
    public boolean isRoot() {
        return false;
    }
}
